<?php
namespace app\common\model;
class ShopFavs extends Common
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'ctime';

    /**
     * 店铺信息表关联
     * @return [type] [description]
     */
    public function shop(){
        return $this->hasOne(Shop::class,'id','shop_id');
    }

    /**
     * 店铺收藏记录
     */
    public function getList($uid,$page=1,$limit=20){
        $where[] =['uid', 'eq', $uid];
        $where[] =['status', 'eq', 1];
        $list = $this::with('shop')
            ->where($where)
            ->order('id desc')
            ->page($page, $limit)
            ->select();
        $count = $this->where($where)->count();
        foreach($list as $k => $v){
            $list[$k]['ctime'] = date('Y-m-d H:i:s',$v['ctime']);
        }
        $result['status']=true;
        $result['data']['list'] = $list;
        $result['data']['count'] = $count;
        return $result;
    }
}
